<?php require_once('./header.php');

$perms = array(
    /* Log In */ array('panel','_checkupdate'),
    /* Manage comics */ array('comic','comicadd','comicedit','comiceditdata','comiceditimg','comicdelete','comicdraft:main','comicdraft:edit','comicdraft:delete','comictags','comicaddcollection','comiceditcollection','comicdeletecollection'),
    /* Manage News */ array('news','newsadd','newsedit','newseditdata','newsdelete','newsdraft:main','newsdraft:edit','newsdraft:delete','newsaddcomment','newseditcomment','newsdeletecomment'),
    /* Manage Plugins */ array('_superuser','plugin','pluginadd','pluginuse','pluginedit','plugindelete','pluginevent'),
    /* Manage Site Templates */ array('_superuser','template','templateeditglobal','templateadd','templateedit','templatedelete','templatepage:add','templatepage:edit','templatepage:delete'),
    /* Manage Users */ array('_superuser','configuser:main','configuser:add','configuser:edit','configuser:delete'),
    /* Manage Usergroups */ array('_superuser','configusergroup:main','configusergroup:add','configusergroup:edit','configusergroup:delete'),
    /* Edit Settings */ array('_superuser','config','configsetting','configcache'),
    /* Apply Updates */ array('_superuser','config','configupdate'),
    /* Uninstall ComicCMS */ array('_superuser','config','configuninstall'),
);

if (isset($_POST['doperms'])) {
    $groupdb = load_db('usergroup');
    $ufile = file('./storage/private/usergroups.php');
    array_shift($ufile);
    array_shift($ufile);
    $usergroups = array();
    foreach ($ufile as $uid => $uline) {
        $usergroup = array('name'=>substr($uline,0,strpos($uline,'|')),'permissions'=>array());
        foreach ($perms as $k => $p) {
            if ($_POST[$k.'_'.$uid]) {
                foreach ($p as $perm) {
                    $usergroup['permissions'][$perm] = 1;
                }
            } else {
                foreach ($p as $perm) {
                    if (!isset($usergroup['permissions'][$perm])) $usergroup['permissions'][$perm] = 0;
                }
            }
        }
        
        $groupdb->save($usergroup);
    }
}



?>
        <h1>OK, usergroups all done</h1>
        <p>That wasn't too bad, now just the templates...</p>
        <p>OK, I'll admit it, templates are the hardest part. But there is a get-out button. You can just switch to the new default template and work from there instead of working to get your current site up to date. I would sugest this route for the majority of you, especially if you've mostly just changed CSS, put in some images/digg buttons, etc.</p>
        <p>It really is the easiest option in most cases and, look, you can even download your old templates so you can work back up really quickly!</p>
        <p><strong>Step 1:</strong> <a href="dtemplate.php" target="_blank">Download your current template</a> <strong>and save it to your computer</strong></p>
        <p><strong>Step 2:</strong> DO STEP 1 FIRST! Then: <a href="step3.php">Overwrite your current template with the new default</a></p>
        
        <h2>No? You really want to upgrade from where you are now?</h2>
        <p><strong>Warning:</strong> We can't carry over any custom pages if you added any. Make sure you <a href="dtemplate.php" target="_blank">download your current template</a> and then you can re-add them easily later on.</p>
        <p>OK then, do you want to <a href="dtemplate.php" target="_blank">download your current template</a> for future reference too? After that, <a href="mtemplate.php">off we go...</a></p>
    </div>
</body>
</html>